/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import interfaces.InternationalizableEntity;
import interfaces.InternationalizableEntityDescription;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "educational_level")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "EducationalLevel.findAll", query = "SELECT e FROM EducationalLevel e ORDER BY e.educationalValue"),
    @NamedQuery(name = "EducationalLevel.findByIdEducationalLevel", query = "SELECT e FROM EducationalLevel e WHERE e.idEducationalLevel = :idEducationalLevel"),
    @NamedQuery(name = "EducationalLevel.findByDescription", query = "SELECT e FROM EducationalLevel e WHERE e.description = :description"),
    @NamedQuery(name = "EducationalLevel.findByEducationalValue", query = "SELECT e FROM EducationalLevel e WHERE e.educationalValue = :educationalValue")})
public class EducationalLevel implements Serializable, Comparable<EducationalLevel>, InternationalizableEntity {
    @OneToMany(mappedBy = "minimumEducationalLevel", fetch = FetchType.LAZY)
    private List<SearchEducationalInfoRequerimentAndOperator> searchEducationalInfoRequerimentAndOperatorList;
    @OneToMany(mappedBy = "minimumEducationalLevel", fetch = FetchType.LAZY)
    private List<SearchEducationalInfoRequerimentOrOperator> searchEducationalInfoRequerimentOrOperatorList;
    @OneToMany(mappedBy = "educationalInfoMinimumEducationalLevel", fetch = FetchType.LAZY)
    private List<Search> searchList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_EDUCATIONAL_LEVEL")
    private Integer idEducationalLevel;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "DESCRIPTION")
    private String description;
    @Basic(optional = false)
    @NotNull
    @Column(name = "EDUCATIONAL_VALUE")
    private int educationalValue;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "educationalLevel", fetch = FetchType.LAZY)
    private List<CandidateEducationalInfo> candidateEducationalInfoList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "educationalLevel", fetch = FetchType.LAZY)
    private List<EducationalLevelDescription> educationalLevelDescriptionList;

    public EducationalLevel() {
    }

    public EducationalLevel(Integer idEducationalLevel) {
        this.idEducationalLevel = idEducationalLevel;
    }

    public EducationalLevel(Integer idEducationalLevel, String description, int educationalValue) {
        this.idEducationalLevel = idEducationalLevel;
        this.description = description;
        this.educationalValue = educationalValue;
    }

    public Integer getIdEducationalLevel() {
        return idEducationalLevel;
    }

    public void setIdEducationalLevel(Integer idEducationalLevel) {
        this.idEducationalLevel = idEducationalLevel;
    }

    @Override
    public String getDescription() {
//        String resDescription=description;
//        Locale currentLocale=FacesContext.getCurrentInstance().getViewRoot().getLocale();
//        if(!getEducationalLevelDescriptionList().isEmpty() && !currentLocale.equals(Locale.ENGLISH)){
//            String localeCode=currentLocale.getLanguage();
//            for(EducationalLevelDescription cd:getEducationalLevelDescriptionList()){
//                if(cd.getLanguage().getCode().equals(localeCode)){
//                    resDescription=cd.getDescription();
//                }
//            }
//        }
//        return resDescription;
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getEducationalValue() {
        return educationalValue;
    }

    public void setEducationalValue(int educationalValue) {
        this.educationalValue = educationalValue;
    }

    @XmlTransient
    public List<CandidateEducationalInfo> getCandidateEducationalInfoList() {
        return candidateEducationalInfoList;
    }

    public void setCandidateEducationalInfoList(List<CandidateEducationalInfo> candidateEducationalInfoList) {
        this.candidateEducationalInfoList = candidateEducationalInfoList;
    }

    @XmlTransient
    public List<EducationalLevelDescription> getEducationalLevelDescriptionList() {
        return educationalLevelDescriptionList;
    }

    public void setEducationalLevelDescriptionList(List<EducationalLevelDescription> educationalLevelDescriptionList) {
        this.educationalLevelDescriptionList = educationalLevelDescriptionList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idEducationalLevel != null ? idEducationalLevel.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof EducationalLevel)) {
            return false;
        }
        EducationalLevel other = (EducationalLevel) object;
        if ((this.idEducationalLevel == null && other.idEducationalLevel != null) || (this.idEducationalLevel != null && !this.idEducationalLevel.equals(other.idEducationalLevel))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.EducationalLevel[ idEducationalLevel=" + idEducationalLevel + " ]";
    }

    @XmlTransient
    public List<Search> getSearchList() {
        return searchList;
    }

    public void setSearchList(List<Search> searchList) {
        this.searchList = searchList;
    }

    @XmlTransient
    public List<SearchEducationalInfoRequerimentAndOperator> getSearchEducationalInfoRequerimentAndOperatorList() {
        return searchEducationalInfoRequerimentAndOperatorList;
    }

    public void setSearchEducationalInfoRequerimentAndOperatorList(List<SearchEducationalInfoRequerimentAndOperator> searchEducationalInfoRequerimentAndOperatorList) {
        this.searchEducationalInfoRequerimentAndOperatorList = searchEducationalInfoRequerimentAndOperatorList;
    }

    @XmlTransient
    public List<SearchEducationalInfoRequerimentOrOperator> getSearchEducationalInfoRequerimentOrOperatorList() {
        return searchEducationalInfoRequerimentOrOperatorList;
    }

    public void setSearchEducationalInfoRequerimentOrOperatorList(List<SearchEducationalInfoRequerimentOrOperator> searchEducationalInfoRequerimentOrOperatorList) {
        this.searchEducationalInfoRequerimentOrOperatorList = searchEducationalInfoRequerimentOrOperatorList;
    }
    
    @Override
    public int compareTo(EducationalLevel el) {
        Integer valueThis=this.getEducationalValue();
        Integer valueOther=el.getEducationalValue();
        return valueThis.compareTo(valueOther);
    }

    @Override
    public Integer getId() {
        return getIdEducationalLevel();
    }

    @Override
    public List<? extends InternationalizableEntityDescription> getDescriptionsList() {
        return getEducationalLevelDescriptionList();
    }
}
